package com.gitee.wsl.compose.state.ext

import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalContext
import androidx.compose.runtime.ProvidedValue
import androidx.compose.runtime.SnapshotMutationPolicy
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.runtime.structuralEqualityPolicy
import com.gitee.wsl.compose.state.S


//本地状态
fun <T> S.localOf(
    policy: SnapshotMutationPolicy<T> = structuralEqualityPolicy(),
    defaultFactory: () -> T
) = compositionLocalOf(policy,defaultFactory)

fun <T> S.staticLocalOf(defaultFactory: () -> T) = staticCompositionLocalOf(defaultFactory)

/**
 * @Composable
 * fun MaterialTheme(
 *     colors: Colors = MaterialTheme.colors,
 *     typography: Typography = MaterialTheme.typography,
 *     shapes: Shapes = MaterialTheme.shapes,
 *     content: @Composable () -> Unit
 * ) {
 *     ...
 *     CompositionLocalProvider(
 *         LocalColors provides rememberedColors,
 *         LocalContentAlpha provides ContentAlpha.high,
 *         LocalIndication provides rippleIndication,
 *         LocalRippleTheme provides MaterialRippleTheme,
 *         LocalShapes provides shapes,
 *         LocalTextSelectionColors provides selectionColors,
 *         LocalTypography provides typography
 *     ) {
 *         ProvideTextStyle(value = typography.body1) {
 *             PlatformMaterialTheme(content)
 *         }
 *     }
 * }
 *
 */

@Suppress("ComposableNaming")
@Composable
fun S.changeLocal(value: ProvidedValue<*>, content: @Composable () -> Unit) = androidx.compose.runtime.CompositionLocalProvider(value, content)

@Suppress("ComposableNaming")
@Composable
fun S.changeLocal(vararg values: ProvidedValue<*>, content: @Composable () -> Unit) = androidx.compose.runtime.CompositionLocalProvider(*values){
    content()
}

@Suppress("ComposableNaming")
@Composable
fun S.changeLocal(context: CompositionLocalContext, content: @Composable () -> Unit) = androidx.compose.runtime.CompositionLocalProvider(context, content)

